package edu.cmu.cs211.bacon.util;

/**
 * A directed edge in a graph, as specified by the nodes which lie at either
 * end.
 * 
 * You may not edit this file.
 */
public class Edge<N> {
	private final N src;
	private final N dest;
	private final double weight;
	
	public N src()
	{
		return src;
	}
	
	public N dest()
	{
		return dest;
	}
	
	public double weight()
	{
		return weight;
	}
	
	/** Creates a new instance of Edge */
	public Edge (N src, N dest, double weight)
	{
		this.src = src;
		this.dest = dest;
		this.weight = weight;
	}

	@Override
	//@SuppressWarnings("unchecked")
	public boolean equals (Object obj)
	{
		if (!(obj instanceof Edge))
			return false;

		@SuppressWarnings("rawtypes")
		Edge e = (Edge) obj;
		return
		  e.weight == weight &&
		  ( src == null && e.src == null || src != null && e.src.equals(src)) &&
		  ( dest == null && e.dest == null || dest != null && e.dest.equals(dest));
	}

	@Override
	public int hashCode ()
	{
		return src.hashCode() ^ (dest.hashCode()<<1) ^ (int)weight;
	}
	
	@Override
	public String toString()
	{
		return "("+src+","+dest+")";
	}
}
